{% load static %}
<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- 上述meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css"
          integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css"
          integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <title>测试狗</title>
</head>
<body>
{#      <div class="container">#}
<div class="row">
    <div class="col">
        <ol class="breadcrumb">
            <li><a href="#">刷新</a></li>
        </ol>
    </div>
</div>
{#      </div>#}
<div class="row justify-content-start">
    <div class="col">
        <div class="col-20 form-group" style="border-bottom: 1px solid #000000"></div>
    </div>
</div>
<div class="alert alert-warning" role="alert">请打开开发者权限、选择不熄屏、确保机器安装 adb 环境！</div>
<form enctype="multipart/form-data" method="post">
    <div class="jumbotron">
        <div class="form-group">
            <label for="exampleInputEmail1">应用包名</label>
            <input type="text" class="form-control" id="appname" aria-describedby="emailHelp">
            <small id="emailHelp" class="form-text text-muted">包名不知道找相关开发或者adb 查询</small>
        </div>
        <div class="form-group">
            <label for="exampleInputEmail1">Activity名</label>
            <input type="text" class="form-control" id="activityname" aria-describedby="emailHelp">
            <small id="emailHelp" class="form-text text-muted">包名不知道找相关开发或者adb 查询</small>
        </div>
        <div class="form-group">
            <input name="file" type="file"/>
        </div>
    </div>
    <div>
        <div class="row">
            <div class="col">
                <table class="table">
                    <thead class="thead-light">
                    <tr>
                        <th scope="col">#</th>
                        <th scope="col">品牌</th>
                        <th scope="col">型号</th>
                        <th scope="col">分辨率</th>
                        <th scope="col">系统版本</th>
                        <th scope="col">选中</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for key, value in appall.items %}
                        <tr>
                            <th scope="row"> {{ key|add:"1" }}</th>
                            <td> {{ value.Mobile_phone_brands }}</td>
                            <td>{{ value.phone_brands_version }}</td>
                            <td>{{ value.phone_px }}</td>
                            <td>{{ value.Android_version }}</td>
                            <td>
                                <div class="form-group form-check">
                                    <input type="checkbox" class="form-check-input"
                                           id={{ value.phone_code }} value={{ value.phone_code }}>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div>{% csrf_token %}
        <input type="button" value="TEST"/>
    </div>
</form>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
        integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
        crossorigin="anonymous"></script>
<script type="text/javascript">
    $(':button').click(function () {
        var formData = new FormData($('form')[0]);// 自动搜索表单信息(表单内没有name属性的input不会被搜索到)，IE<=9不支持FormData
        var checkedlist = $(":checked");
        console.log(checkedlist)
        let caselist = {};
        app_name = $("#appname").val();
        activity_name = $("#activityname").val();
        for (let i = 0; i < checkedlist.length; i++) {
            caselist[i] = checkedlist[i].id
        }
        console.log(caselist);
        appidlist = JSON.stringify(caselist);
        activityname_z = JSON.stringify(activity_name);
        console.log(activityname_z);
        {#appname_z = JSON.stringify(app_name);#}
        {#console.log(appname_z);#}

        console.log(formData);
        $.ajax({
            url: "",
            type: "POST",//方法类型
            cache: false,//
            processData: false,
            contentType: false,
            dataType: "json",
            data: formData,

        });
        $.ajaxSetup({
            data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
        })
        $.post("/polls/app_case/", {
                appidlist,
                activityname_z,
                app_name
            },
            function (data, status) {
                datas = JSON.parse(data)
                console.logdatas()
            });
    });

    function progressHandlingFunction(e) {
        if (e.lengthComputable) {
            $('progress').attr({value: e.loaded, max: e.total});
        }
    }

    function beforeSendHandler() {
        alert("请求前");
    }

    function completeHandler() {
        alert("请求成功");
    }

    function errorHandler() {
        alert("请求错误");
    }
</script>
</body>
</html>
